<template>
    <div>
        <el-form :model="form" :rules="rules" ref="form" v-loading="loading">
            <el-form-item prop="dailyScore" label="日常成绩" label-width="80px">
                <el-input v-model="form.dailyScore" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item prop="examScore" label="考试成绩" label-width="80px">
                <el-input v-model="form.examScore" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item prop=" score" label="总成绩" label-width="80px">
                <el-input v-model="form.score" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot=" footer" class="dialog-footer" style="display: flex; justify-content: flex-end;">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </div>
    </div>
</template>

<script>
import { submitScoreInfo, submitScore } from '@/api/teacher/course';
export default {
    props: ["id"],
    data() {
        return {
            form: {
                dailyScore: "",
                examScore: "",
                score: "",
                id: -1
            },
            loading: false,
            rules: {
                dailyScore: [
                    { required: true, message: "请输入日常成绩", trigger: 'blur' },
                ],
                examScore: [
                    { required: true, message: "请输入考试成绩", trigger: 'blur' },
                ],
                score: [
                    { required: true, message: "请输入总成绩", trigger: 'blur' },
                ]
            }
        }
    },
    methods: {
        getInfo() {
            this.loading = true
            submitScoreInfo(this.id).then(res => {
                // console.log(res)
                this.form = res.data
            }).finally(() => {
                this.loading = false
            })
        },
        submit() {
            this.$refs["form"].validate(f => {
                if (f) {
                    submitScore(this.form).then(res => {
                        if (res.code === 0) {
                            this.$message({
                                type: "success",
                                message: res.data
                            })
                            this.$emit("close")
                        }
                    }).catch(err => {
                        console.log(err)
                        this.$message({
                            type: "error",
                            message: "操作太快了！"
                        })
                    })
                }
            })
        },
        cancel() {
            this.$emit("cancelMarking")
        }
    },
    mounted() {
        this.getInfo()
    }
}
</script>